package com.csj.cloud.front.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.rpc.RpcContext;
import com.csj.cloud.common.entity.Order;
import com.csj.cloud.common.vo.ResultBean;
import com.csj.cloud.core.service.order.OrderService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

/**
 * @Author:ChengshaoJie
 * @Description:
 * @Date:Created in 上午 11:10 2019/11/28 0028
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Reference(group = "other")
    private OrderService orderService;

    @RequestMapping("/getDetail")
    public ResultBean getDetail(Integer id) {
        ResultBean resultBean = new ResultBean();
        if (id != null && id <= 0) {
            return resultBean.setErrorMsg("参数错误");
        }
        return resultBean.setData(orderService.selectById(id));
    }

    @RequestMapping("/createOrder")
    public ResultBean createOrder(Order order) {
        ResultBean resultBean = orderService.addOrder(order);
        Future<ResultBean> future = RpcContext.getContext().getFuture();
        try {
            resultBean = future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return resultBean;
    }
}
